package net.lesscoding.future;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @author eleven
 * @date 2024/10/28 13:52
 * @apiNote
 */
@Slf4j
public class JDKFutureTest {
    @Test
    public void futureTest() throws Exception {
        ExecutorService service = Executors.newFixedThreadPool(2);
        Future<Integer> future = service.submit(() -> {
            log.info("开始执行");
            Thread.sleep(1000);
            return new Random().nextInt(100);
        });
        log.info("等待执行结果");
        log.info("执行结果 {}", future.get() );
    }
}
